/**
 * 
 */
package sistema.contexto.problemas;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;

import sistema.contexto.AvaliacaoBLFacade;



/**
 * @author Thiago Emmanuel Pereira da Cunha Silva, thiago.manel@gmail.com
 * @since 15/04/2006
 */
public class ProblemasTUI {

	@SuppressWarnings("static-access")
	public static void main(String args[]) {
		Option identificadorOption = OptionBuilder.
														withArgName("identificador")
														.hasArg()
														.withDescription("identificador do problema")
														.create("id");
		
		Option especOption = OptionBuilder.
														withArgName("espec")
														.hasArg()
														.withDescription("Especificacao do Prob.")
														.create("espec");
		
		Option idLingOption = OptionBuilder.
																withArgName("idLing")
																.hasArg()
																.withDescription("identificador da liguagem")
																.create("idLing");
		
		Option  idValid = OptionBuilder.
																withArgName("idValid")
																.hasArg()
																.withDescription("identificador do validador")
																.create("idValid");
		
		Option  pathInput = OptionBuilder.
																withArgName("pathInput")
																.hasArg()
																.withDescription("Path do arquivo de entrada")
																.create("pathInput");
		
		Option  pathOutput = OptionBuilder.
																withArgName("pathOutput")
																.hasArg()
																.withDescription("Path do arquivo de saida")
																.create("pathOutput");
		
		Options options = new Options();
		options.addOption(identificadorOption);
		options.addOption(especOption);
		options.addOption(idLingOption);
		options.addOption(idValid);
		options.addOption(pathInput);
		options.addOption(pathOutput);
		
		options.addOption("lista", true , "lista  Linguagens");
		
		HelpFormatter formatter = new HelpFormatter();
		formatter.printHelp( "caos", options );
		
		CommandLineParser parser = new PosixParser();
	    try {
	        CommandLine line = parser.parse( options, args );
	        try {
	        	new AvaliacaoBLFacade().criaProblema(line.getOptionValue( "id"),
						  line.getOptionValue("espec"),
						  line.getOptionValue("idLing"),
						  line.getOptionValue("idValid"),
						  line.getOptionValue( "pathInput"), 
						  line.getOptionValue( "pathOutput"));
			} catch (IllegalArgumentException e) {
				System.out.println(e.getMessage());
			}
	        
	        if(line.hasOption("lista")){
	        	System.out.println(new AvaliacaoBLFacade().listaProblemas());
	        }
	    }
	    catch( ParseException exp ) {
	        System.err.println( "Parsing failed.  Reason: " + exp.getMessage() );
	    }
		
	}
}
